using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.UI;
using System.Web.UI.HtmlControls;
namespace Library.WebControls.SimpleTab {
	public class SpTabControlDesign : System.Web.UI.Design.ControlDesigner {
		public override string GetDesignTimeHtml() {
			SpTabControl ctrTab = (SpTabControl)Component;
			StringWriter sw = new StringWriter();
			HtmlTextWriter tw = new HtmlTextWriter(sw);
			HtmlGenericControl tab = new HtmlGenericControl("div");
			tab.Attributes["class"] = "spTabControl";
			if (!String.IsNullOrEmpty(ctrTab.CssFileName)) {
				Control link = BaseControl.CreateResolveClientCssLink(ctrTab.ResolveClientUrl(ctrTab.CssFileName));
				if (link != null) {
					tab.Controls.AddAt(0, link);
				}
			}
			HtmlGenericControl divTitle = new HtmlGenericControl("div");
			divTitle.Attributes["class"] = "spTabTitle";
			tab.Controls.Add(divTitle);

			HtmlGenericControl divTitle1 = new HtmlGenericControl("div");
			divTitle1.Attributes["class"] = "spTabTitle1";
			divTitle.Controls.Add(divTitle1);

			HtmlGenericControl divTitle2 = new HtmlGenericControl("div");
			divTitle2.Attributes["class"] = "spTabTitle2";
			divTitle1.Controls.Add(divTitle2);

			HtmlGenericControl divTitle3 = new HtmlGenericControl("div");
			divTitle3.Attributes["class"] = "spTabTitle3";
			divTitle2.Controls.Add(divTitle3);

			HtmlGenericControl divTitleContent = new HtmlGenericControl("div");
			divTitleContent.Attributes["class"] = "spTabTitleContent";
			divTitle3.Controls.Add(divTitleContent);

			for (int i = 0; i < ctrTab.Tabs.Count; i++) {

				SpTabPage t = ctrTab.Tabs[i];
				//t.ClientId = ctrTab.ClientID + "Tab" + i.ToString();
				HtmlAnchor aMenu = new HtmlAnchor();
				//aMenu.ID = ctrTab.ClientID + "Menu" + i.ToString();
				//t.ClientMenuId = aMenu.ClientID;
				string name = t.Text == null ? t.Name : t.Text;
				aMenu.InnerHtml = "<span><strong>" + name + "</span></strong>";
				if (i == ctrTab.SelectedIndex) {
					aMenu.Attributes["class"] = "active";
				}
				aMenu.HRef = "javascript:" + ctrTab.ClientName + ".ActiveTab(" + i.ToString() + ")";
				divTitleContent.Controls.Add(aMenu);
				HtmlGenericControl tPag = new HtmlGenericControl("div");
				tPag.Attributes["class"] = "spTabContent";

				//tPag.ID = t.ClientId;
				//
				//if (ctrTab.SelectedIndex != i) {
				//tPag.Style.Add(System.Web.UI.HtmlTextWriterStyle.Display, "none");
				//} else {

				//}

				if (ctrTab.SelectedIndex != i) continue;
				tPag.Controls.Add(t);
				tab.Controls.Add(tPag);
			}
			tab.RenderControl(tw);
			return sw.ToString();
		}
	}
}
